//
//  woaOpenAPI+TTAdditions.h
//  tongtong
//
//  Created by xie bin on 12-3-31.
//  Copyright (c) 2012年 SNDA. All rights reserved.
//

// 把原OA2.0中（xiebin实现）关于获取国家列表，和自动识别当前国家的移到这里来
// 由于种种原因不得不用SDO那边提供的.a，哎~~~~~
// 泥玛的大部分协议都知道，就是数据采集的不清楚

#import <Foundation/Foundation.h>
#import "woaOpenAPI.h"

enum _woaErrorCodeEx {
    wecSuccess = 0,     // 操作成功
    wecError = 1        // 操作失败
};
typedef NSInteger woaErrorCodeEx;

@class woaConfigs;
@protocol woaDelegateEx;

@interface WoaOpenApi(TTAdditions)

- (woaConfigs *)getConfigs;

@end

@interface woaOpenAPI_Ex : NSObject 

+ (woaOpenAPI_Ex *)shareWoaOpenAPI_Ex;

@property (readwrite) NSInteger resultCode;
@property (readwrite) NSInteger requestErrorCode;
@property (nonatomic, unsafe_unretained) id <woaDelegateEx> delegate;

// 当前配置相关数据
@property (readwrite, strong) woaConfigs *configs;

/** 当前用户选择的国家代码默认值是-1(自动选择)
 值是woaOpenAPI.configs.countryNames 的位置索引
 */
@property (readwrite) NSInteger countryCodeIndex;

- (void)getConfigData;

- (void)doGetConfigDataResult:(NSDictionary *)dict;

- (NSString *)addCountryCode:(NSString *)phone;

@end

@interface woaConfigEx : NSObject {
@private
    // 取本机的mac地址生成个固定的key用于简单加密信息
    Byte _macXorKey;
    // 用于存取数据
    NSMutableDictionary *_dict;
    NSString *libraryPath;
    NSString *woaDirectory;
    NSString *woaConfigPlist;
}

+ (woaConfigEx *)shareWoaConfigEx;
+ (NSString *) macAddress;
- (BOOL)synchronize;

@property (readonly) NSString *configUrl;

@property (readwrite, copy, setter = setConfigsData:, getter = getConfgisData) NSString *configsData;

// 无线运营商国家代码(取不到则取当前时区的国家代码) 对照表参考 http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
@property (readonly) NSString *isoCountryCode;

/**
 最大重试次数，默认是3
 */
@property (readwrite) NSUInteger maxRetryCount;

/**
 网络操作超时时间
 */
@property (readwrite) NSUInteger timeOutSeconds;


@end

// 配置相关数据(后加的内容，为方便取到支持下发短信的国家代码countryCode)
@interface woaConfigs : NSObject {
@private
    
}

- (id)initWithString:(NSString *)cfgString;

// 注意是本次配置数据的版本号，不是woa的版本号
@property (unsafe_unretained, nonatomic, readonly) NSString *version;
// 总超时，有下行 (单位毫秒)
@property (nonatomic, readonly) NSUInteger timeoutReadSMS;
// 总超时，无下行
@property (nonatomic, readonly) NSUInteger timeoutTryLogin;
// 后台收到客户端短信后，GUID和手机号暂时绑定的失效时间
@property (nonatomic, readonly) NSUInteger timeoutBindMobile;
// 后台GUID的失效时间，到时客户端必须重新获取GUID和特服号
@property (nonatomic, readonly) NSUInteger timeoutGuid;
// 发短信后第一次尝试间隔
@property (nonatomic, readonly) NSUInteger intevalFirstTry;
// 后续尝试间隔
@property (nonatomic, readonly) NSUInteger intevalNextTry;
// 读取下行短信间隔
@property (nonatomic, readonly) NSUInteger intevalReadSMS;
// 国家代码表 (key是国家名称 value是代码 数据都是字符串)
@property (nonatomic, readonly) NSDictionary *countryCode;
// 国家名称NSString数组，使用从服务器端返回的顺序
@property (nonatomic, readonly) NSArray *countryNames;
// 返回当前默认区号索引（位于countryNames中）,-1则表示未找到
@property (nonatomic, readonly) NSInteger defaultCountryIndex;
@property (nonatomic, readonly) NSString *defaultCountryName;
@end

@protocol woaDelegateEx <NSObject>
@optional
/**
 配置信息变化事件configs
 @param code 错误码 wecSuccess则说明woaOpenAPI_Ex.configs数据有变化需要更新
 */
- (void)configsChangedResult:(NSInteger)code;

@end